package tmproject.hlhj.fhp.cartrans.modules

import android.content.Context
import com.example.mymvp.BaseModule
import com.lzy.okgo.model.Response
import tmproject.hlhj.fhp.cartrans.http.Apis
import tmproject.hlhj.fhp.cartrans.http.BaseObserver
import tmproject.hlhj.fhp.cartrans.http.LoadingAction
import tmproject.hlhj.fhp.cartrans.javaBean.BaseBean
import tmproject.hlhj.fhp.cartrans.javaBean.DriverInfoBean
import tmproject.hlhj.fhp.cartrans.javaBean.LearInfoBean
import tmproject.hlhj.fhp.cartrans.javaBean.UnReadNumBean

/**
 * Created by Administrator on 2018/8/26/026.
 */
class HomeModule :BaseModule {
    var listener:OnDriverInfoListener?=null
    fun getDriveInfo(c:Context,token:String?){
        Apis.getDriverInfo(token)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :BaseObserver<Response<DriverInfoBean>>(c){
                                override fun failed(e: Throwable?) {

                                }

                                override fun httpSuccess(t: Response<DriverInfoBean>) {
                                    listener?.gotInfo(t.body())
                                }

                                override fun httpErroCode(baseBean: BaseBean) {

                                }
                            })
                }

    }

    fun getLearnInfo(c:Context,token: String?){
        Apis.getLearnInfo(token)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :BaseObserver<Response<LearInfoBean>>(c){
                                override fun failed(e: Throwable?) {
                                }

                                override fun httpSuccess(t: Response<LearInfoBean>) {
                                    listener?.gotLearnInfo(t.body())
                                }

                                override fun httpErroCode(baseBean: BaseBean) {
                                }
                            })
                }
    }
    fun getUnReadNum(c: Context,token: String?){
        Apis.getUnReadNum(token)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :BaseObserver<Response<UnReadNumBean>>(c){
                                override fun failed(e: Throwable?) {
                                }

                                override fun httpSuccess(t: Response<UnReadNumBean>) {
                                    listener?.gotUnreadNum(t.body())
                                }

                                override fun httpErroCode(baseBean: BaseBean) {
                                }
                            })
                }
    }
    interface OnDriverInfoListener{
        fun gotInfo(driverInfoBean: DriverInfoBean)
        fun gotLearnInfo(learInfoBean: LearInfoBean)
        fun gotUnreadNum(unReadNumBean: UnReadNumBean)
    }
}